package com.nowcoder.community.community.util;

import org.aspectj.lang.ProceedingJoinPoint;
import org.springframework.security.core.parameters.P;

public class RedisKeyUtil {

    private static final String SPLIT = ":";
    private static final String PREFIX_ENTITY_LIKE = "like:entity";
    private static final String PRIFIX_USER_LIKE = "like:user";
    private static final String PRIFIX_FOLLOWEE = "followee";
    private static final String PRIFIX_FOLLOWER = "follower";
    private static final String PRIFIX_KAPTCHA = "kaptcha";
    private static final String PRIFIX_TICKET = "ticket";
    private static final String PRIFIX_USER = "user";
    private static final String PRIFIX_UV = "uv";
    private static final String PRIFIX_DAU = "dau";
    private static final String PREFIX_POST = "post";

    /**
     * 某个实体的赞
     * like:entity:entityType:entityId --> set(userId)
     * @param entityType 实体类型
     * @param entityId 实体id
     * @return
     */
    public static String getEntityLikeKey(int entityType, int entityId){
        return PREFIX_ENTITY_LIKE + SPLIT + entityType + SPLIT + entityId;
    }

    /**
     * 某个用户的赞
     * like:user:userId --> int
     */
    public static String getUserLikeKey(int userId){
        return PRIFIX_USER_LIKE + SPLIT + userId;
    }

    /**
     * 某个用户关注的实体
     * followee:userId:entityType --> zset(entityId, now)
     */
    public static String getFolloweeKey(int userId, int entityType){
        return PRIFIX_FOLLOWEE + SPLIT + userId + SPLIT + entityType;
    }

    /**
     * 某个实体拥有的粉丝
     * follower:entityType:entityId --> zset(userId, now)
     */
    public static String getFollowerKey(int entityType, int entityId){
        return PRIFIX_FOLLOWER + SPLIT + entityType + SPLIT + entityId;
    }

    /**
     * 登录验证码
     */
    public static String getKaptchaKey(String owner) {
        return PRIFIX_KAPTCHA + SPLIT + owner;
    }

    /**
     * 登录的凭证
     */
    public static String getTicketKey(String ticket){
        return PRIFIX_TICKET + SPLIT + ticket;
    }

    /**
     * 用户
     */
    public static String getUserKey(int userId) {
        return PRIFIX_USER + SPLIT + userId;
    }

    /**
     * 单日独立访客(UV)
     */
    public static String getUVKey(String date) {
        return PRIFIX_UV + SPLIT + date;
    }

    /**
     * 区间UV
     */
    public static String getUVKey(String startDate, String endDate) {
        return PRIFIX_UV + SPLIT + startDate + SPLIT + endDate;
    }

    /**
     * 单日活跃用户(DAU)
     */
    public static String getDAUKey(String date) {
        return PRIFIX_DAU + SPLIT + date;
    }

    /**
     * 区间活跃用户
     */
    public static String getDAUKey(String startDate, String endDate) {
        return PRIFIX_DAU + SPLIT + startDate + SPLIT + endDate;
    }

    /**
     * 帖子分数
     */
    public static String getPostScoreKey() {
        return PREFIX_POST + SPLIT + "score";
    }

}
